#!/usr/bin/env python
# -*- coding:utf-8 -*-

from bs4 import BeautifulSoup
from lxml import etree
import requests
import lxml.html

def zhihuLogin():
    session = requests.Session()
    headers = {"User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"}
    html = session.get("https://www.zhihu.com/signup?next=%2F", headers = headers).text
    bs = BeautifulSoup(html, "lxml")

    # bs
    captcha_url = bs.find("img", attrs={"data-tooltip":"看不清楚？换一张"}).get("src")
    print(captcha_url)

    # lxml
    content = lxml.html.document_fromstring(html)
    src = content.xpath('//img[@class="Captcha-englishImg"]/@src')
    print(src)

    # data = {
    #     'username' : '215731932@qq.com',
    #     'password' : 'yzl314159'
    # }
    #
    # reponse = session.post("https://www.zhihu.com/api/v3/oauth/sign_in", data = data, headers = headers)
    # print(reponse.text)



if __name__ == "__main__":
    zhihuLogin()